<template>
	<gui-page ref="guiPage" :customHeader="true">
		<template v-slot:gHeader>
			<nav-bar-custom left-icon="left" :title="$t('distributedEnter.scanRecord')"></nav-bar-custom>
		</template>
		<template v-slot:gBody>
			<view v-if="data.barcodeList.length == 0" class="noticeHooks">
				{{ data.barcodeList.length == 0 ? $t('stockManage.notAvailable') : $t('stockManage.without') }}
			</view>
			<view class="record-card" v-for="(item, index) in data.barcodeList" :key="`${item.barcode}` + `${index}`"
				v-else>
				<uni-icons class="close-icons" type="closeempty" color="#9C9C9C" size="30"
					@click="handelClosePopup(index, item)"></uni-icons>
				<view class="card-mini-head">
					<view class="title-line"></view>
					<text>{{ $t('translationImage.serialNumber') }}：{{ data.barcodeList.length - index }}</text> <text
						style="margin-left: 10px" class="gui-badge demo gui-bg-red gui-color-white"
						v-if="item.isInStock">
						{{ $t('distributedEnter.processed') }}</text>
				</view>
				<view class="custom-card-itemOne">
					<text class="item-info-title">{{ $t('distributedOut.barcode') }}：</text>{{ item.barcode }}
				</view>
				<view class="custom-card-itemOne">
					<text class="item-info-title">{{ $t('distributedEnter.materialCode') }}：</text>{{ item.materialCode
					}}
				</view>
				<view class="custom-card-itemOne">
					<text class="item-info-title">{{ $t('distributedEnter.materialName') }}：</text>{{ item.materialName
					}}
				</view>
				<view class="custom-card-itemOne">
					<text class="item-info-title">{{ $t('distributedEnter.materialSpec') }}：</text>{{ item.materialSpec
		|| '' }}
				</view>
				<view class="custom-card-itemOne">
					<text class="item-info-title">{{ $t('distributedEnter.uom') }}：</text>{{ item.unit }}
				</view>
				<view class="custom-card-itemOne">
					<text class="item-info-title">{{ $t('distributedEnter.qty') }}：</text>{{ item.currentQty }}
				</view>
			</view>
		</template>
	</gui-page>
</template>

<script setup>
import { navigate } from '@/utils/routerSkip.js';
import { useStore } from "vuex";
import { basPdaOperationLogFn } from '@/utils/index.js';
import { OPERATION_DEL, OPERATION_LOOK } from '@/constant/index.js'
import { reactive, onMounted, computed, } from 'vue';
import { deleteOccupancy } from "@/api/api";

let data = reactive({
	barcodeList: [],//条码数组
})

onMounted(() => {
	try {
		let inputParameter = '无'
		let returnParameter = JSON.stringify(data.barcodeList)
		let operationPicture = '成品入库'
		let callInterface = '无'
		let opertionParmes = {
			inputParameter,
			returnParameter,
			operationPicture,
			callInterface,
			responseCode: '无',//返回状态
			errorMessage: '无',//错误信息
			isPass: 'Y',//是否成功 Y N
			operationType: OPERATION_LOOK,
			module: 'WMS',
			source: "PDA",
		}
		basPdaOperationLogFn(opertionParmes)
	} catch (error) {
	}
	// 获取已入库的条码,并给已入库的条码复制 isInStock = true
	const barcodeArr = data.barcodeList.map(item => item.barcode);
	// console.log('barcodeArr', barcodeArr);
	// isBarcodeInStock(barcodeArr).then(res => {
	// 	if (res?.statusCode === 200 && res.data && res.data.length > 0) {
	// 		data.barcodeList.forEach(x => {
	// 			console.log(x.barcode, res.data)
	// 			if (res.data.includes(x.barcode)) {
	// 				x.isInStock = true;
	// 			}
	// 		})
	// 	}
	// })
})

let store = useStore();
data.barcodeList = computed(() => {
	return store.state.finishedProductStorageList
})

const handelClosePopup = (index, item) => {
	try {
			let inputParameter = JSON.stringify('无')
			let returnParameter = JSON.stringify(item)
			let operationPicture = '成品入库'
			let callInterface = '无'
			let opertionParmes = {
				inputParameter,
				returnParameter,
				operationPicture,
				callInterface,
				responseCode: '无',//返回状态
				errorMessage: '无',//错误信息
				isPass:'无',//是否成功 Y N
				operationType: OPERATION_DEL,
				module: 'WMS',
				source: "PDA",
			}
			basPdaOperationLogFn(opertionParmes)
		} catch (error) {
		}
	store.commit('deleteFinishedProductStorage', index)
	//
	uni.$emit('addInventoryCount')
}


</script>

<style></style>
